<?php

namespace App\Http\Controllers\Site;

use App\B2BProject\Admin\Authority\Auth;
use App\B2BProject\Custom\LogisticsServer;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;

class LogisticsServerController extends Controller
{
    //
    public function postFindTruck(Request $request)
    {
        $member = \Auth::user();
        try {
            \DB::transaction(function () use ($request, $member) {
                $validator = Validator::make($request->all(), [
                    'loadpos'   => 'required', // 装车点
                    'unloadpos' => 'required', // 卸货点
                    'goodsdesc' => 'required', // 货物名称
                    'quantity'  => 'required|numeric', //数量
                    'tel'       => 'required|numeric',// 电话

                ]);
                if ($validator->fails()) {
                    return redirect()->back();
                }
                $data = [
                    'load_position'   => $request->input('loadpos'),
                    'unload_position' => $request->input('unloadpos'),
                    'name'            => $request->input('goodsdesc'),
                    'amonut'          => $request->input('quantity'),
                    'phone'           => $request->input('tel'),
                    'member_id'       => $member->id,
                ];
                LogisticsServer::create($data)->save();
            });
            return response()->json('1');

        } catch (ModelNotFoundException $e) {
            throw($e);
        }
    }
}
